/*
 * Copyright 2008 Hector Francisco Hernandez
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

function jsGorilla(canvas)
{
  victoryLabelInit(canvas);
  impactInit(canvas);
  backgroundInit(canvas);
  buildingInit(canvas);
  gorillaInit(canvas, buildingGetLeftGorillaPosition(),
      buildingGetRightGorillaPosition());
  formInit(canvas);
  bananaInit(canvas);

  formGetShoot("left", jsGorillaLeftShoot);
}

function jsGorillaLeftShoot(angle, velocity)
{
  bananaDoShoot(gorillaGetLeftShootPosition()[0],
      gorillaGetLeftShootPosition()[1],
      angle, velocity, jsGorillaLeftShootReturn);
}

function jsGorillaRightShoot(angle, velocity)
{
  bananaDoShoot(gorillaGetRightShootPosition()[0],
      gorillaGetRightShootPosition()[1],
      180 - angle, velocity, jsGorillaRightShootReturn);
}

function jsGorillaLeftShootReturn(result)
{
  if (result == 0) {
    formGetShoot("right", jsGorillaRightShoot);
  }
  else if (result == 1) {
    victoryLabelShow("right");
  }
  else if (result == 2) {
    victoryLabelShow("left");
  }
}

function jsGorillaRightShootReturn(result)
{
  if (result == 0) {
    formGetShoot("left", jsGorillaLeftShoot);
  }
  else if (result == 1) {
    victoryLabelShow("right");
  }
  else if (result == 2) {
    victoryLabelShow("left");
  }
}

